package ch10_thread.thread;

/**
 * 生命周期
 * 1、new新创建线程
 * 2、可运行
 * 3、已终止
 * 4、被阻塞
 * 5、等待
 * 6、计时等待
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class SixLifeCycle01 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println(i);
            }
        });
        // NEW，新建状态
        System.out.println(thread.getState());
        thread.start();
        // RUNNABLE，可运行状态
        System.out.println(thread.getState());
        try {
            Thread.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 即使是在运行中也是RUNNABLE状态，而不是RUNNING
        System.out.println(thread.getState());

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // TERMINATED，已终止状态
        System.out.println(thread.getState());
    }
}
